﻿using System.Xml;

namespace IniFileManager
{
	/// <summary>
	/// Class representing inner structure of a string element
	/// within property defined by library user in ini schema.
	/// </summary>
	internal sealed class IniStringElementSchema : IniElementSchema
	{
		private readonly string defaultValue;

		/// <summary>
		/// Creates "IniStringElementSchema" from xml node in ini schema xml representation.
		/// </summary>
		/// <param name="stringElementNode">Ini string element schema xml node.</param>
		internal IniStringElementSchema( XmlNode stringElementNode )
		{
			// Embedded "IniSchema.xsd"'s definition guarantees existence and format of this attribute:
			this.defaultValue = stringElementNode.Attributes[IniSchemaXsd.ATTRIBUTE_DEFAULT].Value;
		}

		/// <summary>
		/// Boxed default string value of an element into object.
		/// </summary>
		internal override object DefaulValue
		{
			get
			{
				return this.defaultValue;
			}
		}

		/// <summary>
		/// Tells wheather a value is valid within.
		/// </summary>
		/// <param name="boxedValue">Value boxed in object.</param>
		/// <returns>True if value valid within. False if not.</returns>
		internal override bool IsValueValidWithin( object boxedValue )
		{
			return true;
		}

	}
}
